package initializers;

import exceptions.NullCategoryException;
import gui.AbstractMainFrame;
import gui.MenuBar;

import java.util.LinkedHashMap;
import java.util.Map;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import menuActions.AboutMenuAction;
import menuActions.ExitAppAction;
import menuActions.MenuAction;
import menuActions.NullMenuAction;
import configuration.MenuLabelsSettings;

public class MenuBarInitializer implements Initializer<MenuBar>
{
	private MenuBar menuBar;
	private AbstractMainFrame frame;
	
	public MenuBarInitializer(AbstractMainFrame frame, MenuBar menuBar) 
	{
		this.menuBar = menuBar;
		this.frame = frame;
	}
	
	@Override
	public MenuBar initialize() 
	{
		
		if(menuBar != null)
		{
			Map<JMenuItem, MenuAction> fileMenuGroup = new LinkedHashMap<>();
			Map<JMenuItem, MenuAction> aboutMenuGroup = new LinkedHashMap<>();
			
			fileMenuGroup.put(new JMenuItem(MenuLabelsSettings.OPEN_FILE_SUBMENU), new NullMenuAction());
			fileMenuGroup.put(new JMenuItem(MenuLabelsSettings.SAVE_FILE_SUBMENU), new NullMenuAction());
			fileMenuGroup.put(new JMenuItem(MenuLabelsSettings.SAVE_AS_SUBMENU), new NullMenuAction());
			fileMenuGroup.put(new JMenuItem(MenuLabelsSettings.EXIT_SUBMENU), new ExitAppAction());
			
			aboutMenuGroup.put(new JMenuItem(MenuLabelsSettings.ABOUT_SUBMENU), new AboutMenuAction(frame));
			
			JMenu fileMenuMenu = new JMenu(MenuLabelsSettings.FILE_MENU);
			JMenu helpMenuMenu = new JMenu(MenuLabelsSettings.HELP_MENU);
			
			try 
			{
				menuBar.addMenuItem(fileMenuMenu, fileMenuGroup);
				menuBar.addMenuItem(helpMenuMenu, aboutMenuGroup);
				
				return menuBar;
			} 
			catch (NullCategoryException e) 
			{
				e.printStackTrace();
			}
			
		}
		
		return null;
	}	
}
